<template>
  <div class="person">
    <h1>情况一：监视ref定义的基本类型数据</h1>
    <h2>当前求和为：{{ sum }}</h2>
    <button @click="addSum">点我sum+1</button>
  </div>
</template>

<script lang="ts" setup>
import { ref, watch } from 'vue';

let sum = ref(0)

function addSum() {
  sum.value += 1
}

watch(sum, (newVal, oldVal) => {
  console.log(`sum变化了,新的值是${newVal},旧的值是${oldVal}`);
})
</script>

<style scoped>
.person {
  background: darksalmon;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}
</style>